<template>
    <oa-page title="设置" :enable-right="false">
        <div class="input-panel">
            <h2 class="tips">服务器地址</h2>
            <input type="text" class="oa-input-cell" :placeholder="origin" v-model="origin">
        </div>
        <div class="btn-panel">
            <cube-button @click="save" :primary="true">保存</cube-button>
        </div>
        <cube-button @click="getWifi" >获取wifi</cube-button>
        <textarea v-model="json" style="width: 100%;min-height: 200px"></textarea>
    </oa-page>
</template>

<script>
    import OaPage from "../components/oa-page";
    import {getConfig} from "../config";

    export default {
        components: {OaPage},
        name: "notice",
        data() {
            return {
                origin: getConfig().rootUrl,
                wifi: ["dcqwifi3", "dcqwifi1", "DLZX-guest", "DLZX-employee", "dcqwifi2", "dcqwifi4"],
                json:""
            }
        },

        methods: {
            getWifi(){
                try {
                    WifiWizard.startScan(() => {
                        WifiWizard.getScanResults((res) => {
                            console.log(res)
                            let result = {}
                            res.forEach((item)=>{
                                result[item.BSSID] = item.SSID
                            })
                            this.json = JSON.stringify(result)
                            // this.checkWifi(res)
                        }, (error) => {
                            console.log(error)
                            // this.goLocation()
                        });
                        // alert(res)
                    }, (error) => {
                        console.log(error)

                        // this.goLocation()
                        // console.log(error)
                    })
                } catch (e) {
                    console.log(e)
                }
            },
            save() {
                let config = getConfig()
                config.rootUrl = this.origin;

                localStorage.setItem("systemconfig", JSON.stringify(config));
                this.$createToast({
                    txt: '保存成功',
                    type: 'correct',
                    time: 1500,
                })
            }

        }
    }
</script>

<style lang="less">
    @import "../assets/style/theme";

    .input-panel {
        display: flex;
        flex-direction: column;
        .tips {
            font-size: 14px;
            color: #2c2c2c;
            text-align: center;
            line-height: 32px;
            margin-top: 12px;
        }
        .oa-input-cell {
            margin-top: 20px;
            padding-left: 10px;
            padding-right: 10px;
            flex: 1;
            line-height: 44px;
            background: #FFFFFF;
        }
    }

    .btn-panel {
        width: 90%;
        margin: auto;
        margin-top: 32px;
    }
</style>